// stores/counter.js
import axios from 'axios'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore({
  // 设置命名空间
  id: 'counter',
  state: () => {
    return { count: 0, todos: [] }
  },
  // could also be defined as
  // state: () => ({ count: 0 })
  actions: {
    increment() {
      this.count++
    },
    getTodos() {
      axios.get('http://jsonplaceholder.typicode.com/todos').then((res) => {
        this.$patch({
          todos: res.data
        })
      })
    }
  }
})
